<template>
	<view class="container" :class="{'ui-status-register': isStatusComp}">
    <image :src="info.icon" alt=""></image>
		<text class="title">{{info.name}}</text>
		<view v-if="props.childProp == 'success'" class="conter">
			{{info.context}}
		</view>
		<view v-else class="conter1">
			{{info.context}}
		</view>
		<view class="button-view" v-if="!isStatusComp">
			<fui-button size="32" @click="nextStep">{{info.btnText}}
				<template v-if="countdownShow">
					(<fui-count-down  value="4" @end="end" :isDays='false' :isHours='false' :isMinutes='false'
						:isSuspend='isSuspend' :autoStart="false" ref="countdown" color='#fff' size='32' class="count-down"></fui-count-down>s)
				</template>
			</fui-button>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		inject,
		defineProps,
		watch,
		onMounted,
		defineEmits
	} from 'vue';
	const tab = inject('$tab')
	const countdownShow = ref(true)
	const isSuspend = ref(false)
	const props = defineProps({
		childProp: String,
    isStatusComp: Boolean,
    statusTitle: String,
    statusText: String
	})
	const info = ref({
		icon: '',
		name: '',
		context: '',
		aline: '',
		btnText: '',
		contShow: '',
		url: ''
	})
	const countdown = ref();

	// 在组件挂载后获取子组件实例

	function startCountdown(e) {
		countdown.value?.startCountdown();
	}
	
	watch(props, () => {
		// 自动倒计时
		if (countdown.value && countdown.value.startCountdown) {
			countdown.value.startCountdown();
		}
		if (props.childProp == 'success') {
			info.value = {
				icon: '/static/images/icon-success.png',
				name: props.statusTitle ? props.statusTitle : '认证成功',
				context: props.statusText ? props.statusText : '恭喜您，提交的实名信息认证已成功！',
				aline: 'left',
				btnText: '下一步',
				contShow: true,
			}
		} else if (props.childProp == 'supplySuccess') {
			info.value = {
				icon: '/static/images/icon-submit.png',
				name: props.statusTitle ? props.statusTitle : '认证成功',
				context: props.statusText ? props.statusText : '恭喜您，提交的供应链认证信息已成功！',
				aline: 'center',
				btnText: '返回首页',
				contShow: true,
			}
		} else if (props.childProp == 'submit') {
			info.value = {
				icon: '/static/images/icon-submit.png',
				name: props.statusTitle ? props.statusTitle : '认证申请已提交',
				context: props.statusText ? props.statusText : '请耐心等待，平台管理员审核',
				aline: 'center',
				btnText: '返回登录',
				contShow: true,
			}
		} else if (props.childProp == 'fail') {
			info.value = {
				icon: '/static/images/icon-fail.png',
				name: props.statusTitle ? props.statusTitle : '认证失败',
				context: props.statusText ? (props.statusText === 'hide' ? '' : props.statusText) : '认证失败，请重新认证！',
				aline: 'center',
				btnText: '重新认证',
				contShow: false,
			}
		}
	}, {
    immediate: true
  })

	const emit = defineEmits(['end', 'nextStep'])
	// 倒计时结束
	const end = (e) => {
		emit('end', e)
		countdownShow.value = false
		// if(props.childProp == 'success'){
		//   tab.reLaunch(info.value.url)//下一步地址
		// }else if(props.childProp == 'submit'){
		//   tab.reLaunch('pages/login')//登录地址
		// }

	}
	// 跳转下一页
	function endCountdown(){
			countdown.value.endCountdown(true)
		}
	const nextStep = (e) => {
		endCountdown()
		emit('nextStep', e)
		// tab.reLaunch(info.value.url)
	}
</script>

<style lang="scss">
	.icon {
		width: 1em;
		height: 1em;
		vertical-align: -0.15em;
		fill: currentColor;
		overflow: hidden;
	}

	.container {
		position: absolute;
		width: 80%;
		padding: 60rpx;
		box-sizing: border-box;
		font-family: PingFang SC, PingFang SC;
		color: #333333;
		text-align: center;
		background-color: #fff;
		border-radius: 24rpx;

    &.ui-status-register {
      position: relative;
      width: 100%;
    }

		image {
			width: 232rpx;
			height: 232rpx;
		}

		.title {
			font-size: 40rpx;
			font-weight: bold;
			display: block;
			margin: 22rpx 0 40rpx 0;
		}

		.conter {
			font-size: 32rpx;
			color: #999999;
			display: block;
			text-align: left;
			width: 90%;
			margin: 0 auto;
		}

		.conter1 {
			font-size: 32rpx;
			color: #999999;
			display: block;
			text-align: center;
			width: 90%;
			margin: 0 auto;
		}

		.button-view {
			width: 100%;
			margin-top: 68rpx;

			.count-down {
				:deep(.fui-count__down-item) {
					background-color: rgba(0, 0, 0, 0) !important;
					border: 0px !important;
				}
			}
		}
	}
</style>